package ai.fabu.dataplatform.bean.groupdata;

import ai.fabu.dataplatform.utils.TimeUtil;
import com.google.common.primitives.Longs;
import lombok.Setter;
import lombok.Value;
import lombok.experimental.NonFinal;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.util.Map;

import static ai.fabu.dataplatform.constant.ConstantName.*;

@Value
@Document(collection = "group")
@CompoundIndexes({
        @CompoundIndex(def = "{'group_name':1}", unique = true)
})
public class GroupData {
    public static GroupData staticGroupData(String groupName, String groupPath, Map<String, byte[]> metadata){
        metadata.put(CREATE_TIME, TimeUtil.getNowTimestampLong().toString().getBytes());
        metadata.put(UPDATE_TIME, TimeUtil.getNowTimestampLong().toString().getBytes());
        return new GroupData(null, groupName, groupPath, metadata);
    }

    @Id
    @NonFinal
    @Setter
    ObjectId groupId;
    @Field(GROUP_NAME)
    String groupName;
    @Field(GROUP_PATH)
    String groupPath;
    Map<String, byte[]> metadata;
}
